package model;

import authentication.ejb.usermanagement.User;
import dtos.ExcursionDTO;
import dtos.ExcursionPersTPDTO;
import dtos.HotelDTO;
import dtos.InvitationDTO;
import dtos.MeanOfTransportationDTO;
import dtos.PersonalizedTPDTO;
import dtos.PredefinedTPDTO;
import dtos.TransportationTypeDTO;
import dtos.TripDTO;
import dtos.UserDTO;

public class GetEntities {

	public Excursion getExcursionEntity(ExcursionDTO edto){
		Excursion e = new Excursion();
		e.setArrivalPlace(edto.getArrivalPlace());
		e.setCost(edto.getCost());
		e.setExcursionID(edto.getExcursionID());
		e.setMeetingPlace(edto.getMeetingPlace());
		e.setMeetingTime(edto.getMeetingTime());
		e.setName(edto.getName());
		for (ExcursionPersTPDTO exc : edto.getExcursionPersTps()){
			e.getExcursionPersTps().add(getExcursionPersTPEntity(exc));
		}
		
		return e;
	}
	
	public Excursion getExcursionEntityWithoutExcPersTP(ExcursionDTO edto){
		Excursion e = new Excursion();
		e.setArrivalPlace(edto.getArrivalPlace());
		e.setCost(edto.getCost());
		e.setExcursionID(edto.getExcursionID());
		e.setMeetingPlace(edto.getMeetingPlace());
		e.setMeetingTime(edto.getMeetingTime());
		e.setName(edto.getName());

		return e;
	}
	
	public ExcursionPersTP getExcursionPersTPEntity(ExcursionPersTPDTO edto){
		ExcursionPersTP e = new ExcursionPersTP();
		e.setDate(edto.getDate());
		e.setExcursionPersID(edto.getExcursionPersID());
		e.setExcursion(getExcursionEntityWithoutExcPersTP(edto.getExcursion()));
		e.setPersonalizedTp(getPersonalizedTPEntityWithoutExcPersTP(edto.getPersonalizedTp()));
		return e;
	}
	
	public Hotel getHotelEntity(HotelDTO hdto){
		Hotel h = new Hotel();
		h.setArrivalPlace(hdto.getArrivalPlace());
		h.setClassification(hdto.getClassification());
		h.setCost(hdto.getCost());
		h.setHotelID(hdto.getHotelID());
		h.setName(hdto.getName());
		h.setStreetName(hdto.getStreetName());
		h.setStreetNumber(hdto.getStreetNumber());
		return h;
	}
	
	public Invitation getInvitationEntity(InvitationDTO idto){
		Invitation i = new Invitation();
		i.setInvitationID(idto.getInvitationID());
		i.setInvited(idto.getInvited());
		i.setPersonalizedTp(getPersonalizedTPEntity(idto.getPersonalizedTp()));
		i.setUser(getUserEntity(idto.getUser()));
		return i;
	}
	
	public MeanOfTransportation getMeanOfTransportationEntity(MeanOfTransportationDTO mdto){
		MeanOfTransportation m = new MeanOfTransportation();
		m.setCost(mdto.getCost());
		m.setDepartureTime(mdto.getDepartureTime());
		m.setDuration(mdto.getDuration());
		m.setTransportationID(mdto.getTransportationID());
		m.setTransportationType(getTransportationTypeEntity(mdto.getTransportationType()));
		m.setTrip(getTripEntity(mdto.getTrip()));
		
		return m;
	}
	
	public PersonalizedTP getPersonalizedTPEntity(PersonalizedTPDTO pdto){
		PersonalizedTP p = new PersonalizedTP();
		p.setDateOfDeparture(pdto.getDateOfDeparture());
		p.setDateOfReturn(pdto.getDateOfReturn());
	/*	for (ExcursionDTO e : pdto.getExcursions()){
			p.addExcursion(getExcursionEntity(e));
		}*/
	

		p.setHotelBean(getHotelEntity(pdto.getHotelBean()));


		
		p.setMeanOfTransportation1(getMeanOfTransportationEntity(pdto.getMeanOfTransportation1()));
		p.setMeanOfTransportation2(getMeanOfTransportationEntity(pdto.getMeanOfTransportation2()));
		
		p.setNomberOfPeople(pdto.getNomberOfPeople());
		p.setTravelID(pdto.getTravelID());
		p.setUser(getUserEntity(pdto.getUser()));
		p.setConfirmed(pdto.getConfirmed());
		/*
		for (ExcursionPersTPDTO exc : pdto.getExcursionPersTps()){
			p.getExcursionPersTps().add(getExcursionPersTPEntity(exc));
		}
		*/
		return p;
	}
	
	public PersonalizedTP getPersonalizedTPEntityWithoutExcPersTP(PersonalizedTPDTO pdto){
		PersonalizedTP p = new PersonalizedTP();
		p.setDateOfDeparture(pdto.getDateOfDeparture());
		p.setDateOfReturn(pdto.getDateOfReturn());
		/*for (ExcursionDTO e : pdto.getExcursions()){
			p.addExcursion(getExcursionEntity(e));
		}
		p.setHotelBean(getHotelEntity(pdto.getHotelBean()));
		p.setMeanOfTransportation1(getMeanOfTransportationEntity(pdto.getMeanOfTransportation1()));
		p.setMeanOfTransportation2(getMeanOfTransportationEntity(pdto.getMeanOfTransportation2()));
		
		p.setNomberOfPeople(pdto.getNomberOfPeople());
		p.setTravelID(pdto.getTravelID());
		p.setUser(getUserEntity(pdto.getUser()));
		p.setConfirmed(pdto.getConfirmed());*/

		return p;
	}
	
	public TransportationType getTransportationTypeEntity(TransportationTypeDTO tdto){
		TransportationType t = new TransportationType();
		t.setCompany(tdto.getCompany());
		t.setFlightClass(tdto.getFlightClass());
		t.setTrainClass(tdto.getTrainClass());
		t.setTransportationTypeID(tdto.getTransportationTypeID());
		t.setType(tdto.getType());
		t.setVehicleType(tdto.getVehicleType());
		return t;
	}
	
	public Trip getTripEntity(TripDTO tdto){
		Trip t = new Trip();
		t.setArrivalPlace(tdto.getArrivalPlace());
		t.setDeparturePlace(tdto.getDeparturePlace());
		t.setTripID(tdto.getTripID());
		return t;
	}
	
	public User getUserEntity(UserDTO udto){
		User u = new User(udto);
		return u;
	}
	
	public PredefinedTP getPredefinedTPEntity(PredefinedTPDTO pdto){
		PredefinedTP p = new PredefinedTP();
		for (ExcursionDTO e : pdto.getExcursions()){
			p.addExcursion(getExcursionEntity(e));
		}

		p.setHotelBean(getHotelEntity(pdto.getHotelBean()));
		p.setMeanOfTransportation1(getMeanOfTransportationEntity(pdto.getMeanOfTransportation1()));
		p.setMeanOfTransportation2(getMeanOfTransportationEntity(pdto.getMeanOfTransportation2()));
		p.setTravelID(pdto.getTravelID());
		p.setUser(getUserEntity(pdto.getUser()));
		return p;
	}
	

	
}
